fit(X_training_questions, y_training_answers)
To understand what fit() does look at train_test_split() below
train_test_split() splits the data into training(question, answer).
Validation(question, answer)
Now model has to be trained on training(question, answer). fit() does
the same.
It takes your training data (X_train) and matches them to your target
values (y_train). It looks for patterns, and trains the model
fit(X_traning_questions, y_training_answers, sample_weight=None)
mean_absolute_error(y_validation_answers, predictions)
This is the "grading" step. It tells exactly how wrong our model's predictions from predict() were, on average, compared to the actual real-world prices.
mean_absolute_error(y_validation_answers, predictions)
Lower MAE(better is the model) means model is near to the prediction
predict(X_validation_questions)
Once the model has learned the patterns, it is time to test its
knowledge.
predict takes validation input and provides validation output
prediction = model.predict(X_validation_questions)
// prediction has to compared against y_validation_answers
RandomForestRegressor()
RandomForestRegressor is a type of Regression model
RandomForestRegressor(n_estimators=100, *, criterion='squared_error', max_depth=None,
min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0,
max_features=1.0, max_leaf_nodes=None, min_impurity_decrease=0.0,
bootstrap=True, oob_score=False, n_jobs=None, random_state=None,
verbose=0, warm_start=False, ccp_alpha=0.0, max_samples=None,
monotonic_cst=None)
SimpleImputer()
Create an imputer to fill missing values.
By default, SimpleImputer replaces missing numeric values with the mean
of that column. Example:
If Rooms has values [2, 3, NaN, 4], the NaN may be replaced by 3.0
my_imputer = sklearn.impute.SimpleImputer()
# If X_train had:
# Rooms Distance
# 2 5.0
# NaN 7.2
# 3 NaN
imputed_X_train = pd.DataFrame(my_imputer.fit_transform(X_train))
# Then after imputation:
# Rooms Distance
# 2.0 5.0
# 2.5 7.2
# 3.0 6.1 //Replaces missing values in X_train with average
train_test_split()
Divide the data into two distinct sets:
- Data1: training your model
- Data2 evaluating its performance.
Why this is important? you should never evaluate your model on
the same data it used to learn doing so leads to "overfitting" (the
model simply memorizing the answers instead of learning patterns).
# Split the incoming data into
# |- Training question, answers: X_train, y_train (Practice Questions and Answers)
# |- Validation questions, answers: X_valid, y_valid. Once model is trained the check how its working(Final questions and answers)
// X_training_questions, X_validation_questions
// y_training_answers, y_validation_answers
X_train, X_test, y_train, y_test = train_test_split(*arrays, test_size=None,
train_size=None, random_state=None,
shuffle=True, stratify=None)
# 80% of the rows go into training, 20% go into validation.
X_train, X_valid, y_train, y_valid = train_test_split(
X_dataframe_without_objects, y_dataframe_price, train_size=0.8, test_size=0.2, random_state=0
)